﻿using Iworld.Backstage.Framework;
using Iworld.Backstage.Framework.AdministratorService;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Backstage
{
    /// <summary>
    /// 统一获取管理员信息
    /// </summary>
    public class AdministratorAwareUserControl : UserControl
    {
        public AdministratorAwareUserControl()
        {
            this.Loaded += MeLoaded;
        }

        /// <summary>
        /// 管理员组
        /// </summary>
        public AdministratorGroupExport AdministratorGroup
        {
            get { return (AdministratorGroupExport)GetValue(AdministratorGroupProperty); }
            set { SetValue(AdministratorGroupProperty, value); }
        }

        /// <summary>
        /// 管理员
        /// </summary>
        public AdministratorExport Administrator
        {
            get { return (AdministratorExport)GetValue(AdministratorProperty); }
            set { SetValue(AdministratorProperty, value); }
        }

        void MeLoaded(object sender, RoutedEventArgs e)
        {
            if (DataManager.HaveValue<AdministratorExport>(DataKey.Administrator_Info))
            {
                Administrator = DataManager.GetValue<AdministratorExport>(DataKey.Administrator_Info);
                AdministratorGroup = Administrator.Group;
            }

        }

        public static readonly DependencyProperty AdministratorGroupProperty =
            DependencyProperty.Register("AdministratorGroup", typeof(AdministratorGroupExport), typeof(AdministratorAwareUserControl), new PropertyMetadata(null));

        public static readonly DependencyProperty AdministratorProperty =
            DependencyProperty.Register("Administrator", typeof(AdministratorExport), typeof(AdministratorAwareUserControl), new PropertyMetadata(null));

    }
}
